<?php

namespace app\index\controller;

use think\facade\Db;
use think\facade\View;

class Index
{
    public function index()
    {
        $all = Db::name('order')->where('city', 1)->select()->toArray();
//        var_dump($all);
        foreach ($all as $k => $v) {
            $city = Db::name('users')->where('id', $v['uid'])->value('city');
//            var_dump($city);exit;
            if (!$city) {
                Db::name('order')->where('id', $v['id'])->update(['city' => '东莞']);
            } else {
                $allcn = preg_match("/[\x7f-\xff]/", $city);
//                var_dump($v['id'],$v['uid'],$city,$allcn);exit;
                if ($allcn) {
                    if (strrpos($city, '市')) {
                        $city = substr_replace($city, '', strrpos($city, '市'));
                    }
//                    var_dump($v['uid'], $city, $allcn);exit;
                    Db::name('order')->where('id', $v['id'])->update(['city' => $city]);
                } else {
                    Db::name('order')->where('id', $v['id'])->update(['city' => '其他']);
                }
            }
//
        }

//        var_dump($all);

        exit;
        return View::fetch();
    }

    public function sss()
    {
        hook('testhook', ['id' => 1]);
    }
}